﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MockupDesigner.Items;
using System.Windows.Input;
using System.Windows;

namespace MockupDesigner.Editors.TextEditors
{
    public class NumericUpDownEditor : TextEditorBase
    {
        private NumericUpDownItem itemToEdit;

        public override void element_LostFocus(object sender, RoutedEventArgs e)
        {
            decimal result;
            if (decimal.TryParse(base.element.Text, out result))
            {
                this.itemToEdit.Value = result;
            }
        }

        public override void element_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                element_LostFocus(sender, e);
            }
        }

        public override void SetItem(ItemBase itemToEdit)
        {
            base.SetItem(itemToEdit);
            this.itemToEdit = itemToEdit as NumericUpDownItem;
            base.element.Text = this.itemToEdit.Value.ToString();
        }
    }
}
